package cn.zjitc.quickstart.user.controller;

import cn.zjitc.quickstart.user.service.UserService;
import cn.zjitc.quickstart.user.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
public class LoginConroller {
    @Autowired
    private UserService userService;
    @RequestMapping("/login")
    public String login(String username, String password, HttpSession session){
        User user = userService.login(username,password);
        if(user!=null){
            //登录成功  将user存储到session
            session.setAttribute("user",user);
            return "redirect:/index.jsp";
        }
        return "redirect:/user/login.jsp";
    }
    @RequestMapping("/excep")
    public String excep(){
        int i = 1/0;
        return "redirect:/index.jsp";
    }

}
